// JavaScript Documen
var adTimeoutID;
var menuTimeoutID;
var scrollTimeoutID;
var zuheID;
var notClick = true;
var cartTimeoutID;
function hotImg(num){
	if (num=="")num=1;
	num=num-0;
	var i=0;
	$(".imgGroup a").hide().each(function (){
		i++;
		if (i==num){
			$(this).show();
		}
	});
}

function triggers(e){
	$(".triggers li a").removeClass("on");
	if (e.target != null && e.target != ""){
		$(e.target).addClass("on");
		hotImg($(e.target).text());
	}else{
		if (e.nodeName == "A"){
			$(e).addClass("on");
		}else{
			$("a",e).addClass("on");
		}
		hotImg($(e).text());
	}
	resetTime();
}

function resetTime(){
	window.clearTimeout(adTimeoutID);
	adTimeoutID = window.setTimeout(autoTrigger,3000);
}

function autoTrigger(){
	if ($(".triggers li a.on").text()-0==6){
		triggers($(".triggers li:first a")[0]);
	}else{
		triggers($(".triggers li a.on").parent().next());
	}
}

function indexInit(){
	$(".triggers li").bind("mouseover",triggers);
	adTimeoutID = window.setTimeout(autoTrigger,3000);
		
	$(".shoukuaiCon .m1 a").hover(function(){
		$(".shoukuaiCon ul").removeClass("on");
	},function(){
	});
	
	$(".shoukuaiCon .m2 a").hover(function(){
		$(".shoukuaiCon ul").addClass("on");
	},function(){
	});
	$(".hotImg .imgGroup").hover(function(){
		window.clearTimeout(adTimeoutID);
	},function(){
		resetTime();
	});
	
	$(".shoukuaiCon li").bind("mouseover",showBuy);
	
	$(".gonggao .gonggaoCon li.cur a").bind("mouseover",showGongGao);
	
	$(".qikanCon .nov li a").bind("mouseover",showBook);
	
	$(".centerCorner .zhuanqu .leftscroll").click(function(){
		if (notClick){
			notClick=false;
			/*var count = $(".centerCorner .zhuanqu .qianggouboxcount");
			$(".centerCorner .zhuanqu .qianggouboxcount").animate({marginLeft:"-496px"},"slow","",function(){
				$(".centerCorner .zhuanqu .qianggoubox:first").appendTo(count);
				count.css("margin-left","0");
				notClick=true;
			});*/
			
			$(".centerCorner .zhuanqu .qianggoubox:first").fadeOut('slow', function() {
				$(".centerCorner .zhuanqu .qianggoubox:first").prependTo($(".centerCorner .zhuanqu .qianggouboxcount"));
				$(".centerCorner .zhuanqu .qianggoubox:first").fadeIn('slow', function() {
					notClick=true;
				});
			});
		}
	});
	
	$(".centerCorner .zhuanqu .rightscroll").click(function(){
		if (notClick){
			notClick=false;
			/*var count = $(".centerCorner .zhuanqu .qianggouboxcount");
		
			$(".centerCorner .zhuanqu .qianggoubox:last").prependTo(count);
			count.css("margin-left","-496px");
			
			count.animate({marginLeft:"0"},"slow","",function(){
				notClick=true;
			});*/
			
			$(".centerCorner .zhuanqu .qianggoubox:first").fadeOut('slow', function() {
				$(".centerCorner .zhuanqu .qianggoubox:last").prependTo($(".centerCorner .zhuanqu .qianggouboxcount"));
				$(".centerCorner .zhuanqu .qianggoubox:first").fadeIn('slow', function() {
					notClick=true;
					$(this).css('filter','');
				});
			});
		}
	});
	
	var qianggoubox = $(".centerCorner .zhuanqu .qianggoubox");
	var width = ((qianggoubox.length-0)*(qianggoubox.width()-0)) + "px"
	$(".centerCorner .zhuanqu .qianggouboxcount").width(width);
}

function channelInit(){
	$("#mainCol .dinggou .dinggoutitle li").click(function(){
		if (this.className=="title"){
			$(this).parent().removeClass("on");
			$("#mainCol .dinggou .newdinggou").show();
			$("#mainCol .dinggou table").show();
			$("#mainCol .dinggou .youli").hide();			
		}else{
			$(this).parent().addClass("on");
			$("#mainCol .dinggou table").hide();
			$("#mainCol .dinggou .newdinggou").hide();
			$("#mainCol .dinggou .youli").show();
		}
	});
	
	$("#mainCol .bookinfo .infotab li").click(function(){
		$("#mainCol .infotab li").removeClass("on");
		this.className="on";
		
		$("#mainCol .info").hide();
		$("#mainCol .info[group="+this.attributes.group.value+"]").show();
	});
	
	$("#mainCol .bookinfo div.info ul ul li").mouseover(function(){
		$(this).parent().css("background-image","url(images/"+this.className+".png)");
		$("#mainCol .bookinfo div.info[group=group2] ul .starnum").html(this.className.replace("star",""));
	});
	
	$("#mainCol .bookinfo div.info .t1 input").hover(function(){
		$("#mainCol .bookinfo .pingfeninfo").show();
	},function(){
		$("#mainCol .bookinfo .pingfeninfo").hide();
	});
	
	$("#mainCol .dinggou table tbody input:checkbox").change(function(){	
		if(this.checked){
			$("#mainCol .dinggou table tbody input:checkbox").removeAttr("checked");
			this.checked=true;
			initPrice();
			$("#mainCol .dinggou table tfoot input").removeAttr("disabled");
		}else{
			var trObj=$(this).parents("tr");
			$("select",trObj).attr("disabled","disabled");
			$(".taoshu",trObj).attr("disabled","disabled");
			$("#mainCol .dinggou table tfoot .booknum").html("0");
			$("#mainCol .dinggou table tfoot .price").html("0.00");
			
			if($(".type:checked",trObj).length==0){
				$("#mainCol .dinggou table tfoot input").attr("disabled","disabled");
			}
		}
	});
	
	$("#mainCol .dinggou table tbody input:text").keyup(function(){
		if (this.value-0<1){
			this.value=1;
		}
		priceCalculate($(this).parents("tr"));
	});
	
	$("#mainCol .numbox ul li.up").click(function(){
		var numbox = $("input.taoshu",$(this).parents("tr"));
		
		if (!numbox.get(0).disabled){
			var num = numbox.val() - 0 + 1;
			numbox.val(num);
		
			priceCalculate($(this).parents("tr"));
		}
	});
	$("#mainCol .numbox ul li.down").click(function(){
		var numbox = $("input.taoshu",$(this).parents("tr"));
		
		if (!numbox.get(0).disabled){
			var num = numbox.val() - 1;
			if (num<1){
				num=1;
			}else{
				numbox.val(num);
		
				priceCalculate($(this).parents("tr"));
			}
		}
	});
}

function menuInit(){
	$("#innerHeader .menu2 li.m1").hover(showMenu,createHideCache);
	
	$("#innerHeader .menu2 li.m3,#innerHeader .menu2 li.m2,#innerHeader .cartlist").hover(function(){
		window.clearTimeout(cartTimeoutID);
		$("#innerHeader .cartlist").show();
	},function(){
		cartTimeoutID = window.setTimeout(closeCartList,50);
	});
	
	$("#innerHeader .popupMenu").hover(clearHideCache,createHideCache);
	
	$("#innerHeader .popupMenu dl a").bind("mouseover",showSubMenu);
	
	$("#innerHeader .popupMenu .popupMenuCon .num li").bind("mouseover",showSubBook);
	
	$("#innerHeader .cartlist .del").click(function(e){
		var catID = this.parentNode.attributes.catid.value;
		removeOrder(catID,1);
	});
	
	$(".topsearch .searchtext").focus(function(){
		if (this.value == "输入活动邀请码"){
			this.value = "";
		}
	}).blur(function(){
		if (this.value == ""){
			this.value = "输入活动邀请码";
		}
	})
}
function removeCart(e){
	var name = e.find(".title a").html()
		
	e.remove();
	
	msgBox2("提示","“"+name+"” 移除成功");
	
	var num=$("#innerHeader .cartlist .item").length;
	$("#innerHeader .cartlist .count strong,#innerHeader .menu2 .m3 span").html(num);
	if (num==0){
		$("#innerHeader .cartlist .null").show();
		$("#innerHeader .cartlist .count").hide();
	}
}

function closeCartList(){
	$("#innerHeader .cartlist").hide();
}

function showSubMenu(e){
	$("dt",e.target.parentNode.parentNode.parentNode).removeClass("on");
	$(e.target.parentNode).addClass("on");
	
	var bid = e.target.parentNode.attributes.bid.value;
	$(".divs",e.target.parentNode.parentNode.parentNode).hide();
	$(".divs",e.target.parentNode.parentNode.parentNode)[bid].style.display = "block";
}

function showSubBook(e){
	$("li",e.target.parentNode).removeClass("on");
	$(e.target).addClass("on");
	
	var bid = $(e.target).html() - 1;
	$(".book",e.target.parentNode.parentNode).hide();
	$(".book",e.target.parentNode.parentNode)[bid].style.display = "block";
}

function showMenu(e){
	clearHideCache();
	hideMenu();
	$(this).addClass("on");
	$("#innerHeader .popupMenu").show();	
}

function getOffsetLeft(o)
{
    var left=0;
    var offsetParent = o;
    while (offsetParent!=null && offsetParent!=document.body)
    {
        left+=offsetParent.offsetLeft;
        offsetParent=offsetParent.offsetParent;
    }
    return left;
}

function createHideCache(){
	menuTimeoutID = window.setTimeout(hideMenu,50);
}

function clearHideCache(){
	window.clearTimeout(menuTimeoutID);
}
function hideMenu(){
	$("#innerHeader .popupMenu").hide();
	$("#innerHeader .menu2 li.m1").removeClass("on");
}

function showBuy(e){
	$(".shoukuaiCon div").hide();
	$(".shoukuaiCon div[group="+$(e.target).parent()[0].className+"]").show();
}

function showGongGao(e){
	var target = $(e.target);
	
	$(".gonggao .gonggaoCon li.on").removeClass("on");
	$(target).parent().addClass("on");
	$(".gonggao .gonggaoCon p").hide();
	$(".gonggao .gonggaoCon p[group="+target.text()+"]").show();
	$(".gonggao .gonggaoCon li.btn3 .btn").hide();
	$(".gonggao .gonggaoCon li.btn3 .btn").get(target.text() - 1).style.display = "block";
}

function showBook(e){
	$(".qikanCon li a").removeClass("on");
	$(e.target).addClass("on");
	$(".qikanCon .booklist").hide();
	$(".qikanCon .booklist[group="+$(e.target).parent()[0].className+"]").show();
}

function changeTwoDecimal_f(x)
{
   var f_x = parseFloat(x);
   if (isNaN(f_x))
   {
      alert('function:changeTwoDecimal->parameter error');
      return false;
   }
   var f_x = Math.round(x*100)/100;
   var s_x = f_x.toString();
   var pos_decimal = s_x.indexOf('.');
   if (pos_decimal < 0)
   {
      pos_decimal = s_x.length;
      s_x += '.';
   }
   while (s_x.length <= pos_decimal + 2)
   {
      s_x += '0';
   }
   return s_x;
}

function isNum(num){
	var reg=/^(0|([1-9]\d*))$/;
	if (!reg.test(num.value)){
		num.value = 1;
		return false;
	}
	return true;
}

function initBS(){
	$(".nav .navtab li").click(function(e){
		var group = this.attributes.group.value;
		
		$("li",this.parentNode).removeClass("cur");
		$(this).addClass("cur");
		
		this.parentNode.parentNode.className="nav n"+group;
		
		$(".navcontent",this.parentNode.parentNode).hide();
		$(".navcontent",this.parentNode.parentNode)[group-1].style.display="block";
  });
	
	$(".maincol .tab li").click(function(e){
		var group = this.attributes.group.value - 0;
		
		$("li",this.parentNode).removeClass("cur");
		$("li",this.parentNode).removeClass("firstcur");
		if (group==1){
			this.className="firstcur";
		}else{
			this.className="cur";
		}
		
		$(".maincol .bsdata table").hide();
		$(".maincol .bsdata table")[group-1].style.display="block";
	});
	
}

function initDingDan(){
	$("#subCol .subcontent2 .dd").mouseover(function(){
		$(".ddplus",this.parentNode.parentNode).hide();
		$(".ddplus",this.parentNode).show();
		
		$("dd",this.parentNode.parentNode).removeClass("cur");
		this.parentNode.className="cur";
	});

	$("#mainCol table tr .taoshu").keyup(function(e){
		if(isNum(e.target)){
			if(e.target.value==0)e.target.value=1;
			
			dingDanChanage(e.target);
		}
	});
	
	$("#mainCol table tr li.up").click(function(e){
		var taoshu=$(".taoshu",$(e.target).parents(".numbox")).get(0);

		taoshu.value=taoshu.value-0+1;
		dingDanChanage(taoshu);
	});
	$("#mainCol table tr li.down").click(function(e){
		var taoshu=$(".taoshu",$(e.target).parents(".numbox")).get(0);
		
		if (taoshu.value-0>1){
			taoshu.value=taoshu.value-1;
			dingDanChanage(taoshu);
		}
	});
}

function dingDanChanage(e){
	var taoshu=e.value;
	var price=$(".price .singleprice",$(e).parents("tr")).html();
	var zhekou=$(".zhekou span",$(e).parents("tr")).html();
	var jifen=$(".jifen .singlejifen",$(e).parents("tr")).html();

	$(".price .countprice",$(e).parents("tr")).html(changeTwoDecimal_f(taoshu*price*zhekou));
	$(".jifen .countjifen",$(e).parents("tr")).html(jifen*taoshu);
	
	
	var heji=0;
	var zhekouheji=0;
	var yuanshi=0;
	
	$("#mainCol table tr .countprice").each(function(){
		heji=heji+(this.innerHTML-0);
		var curTaoshu=$(".taoshu",$(this).parents("tr")).val();
		var curPrice=$(".price .singleprice",$(this).parents("tr")).html();
		
		yuanshi=yuanshi+(curTaoshu*curPrice);
		zhekouheji=zhekouheji+((curTaoshu*curPrice)-(this.innerHTML-0));
	});
	
	$("#mainCol .dingdanbottom .yuanshi").html(changeTwoDecimal_f(yuanshi));
	$("#mainCol .dingdanbottom .heji").html(changeTwoDecimal_f(heji));
	$("#mainCol .dingdanbottom .zhekou").html(changeTwoDecimal_f(zhekouheji));
	
}

function initPrice(){
	$("#mainCol .dinggou table select").attr("disabled","disabled");
	$("#mainCol .dinggou table .taoshu").attr("disabled","disabled");
	
	var type = $("#mainCol .dinggou table input.type:checked");
	if (type.length==0){
		$("#mainCol .dinggou table tfoot .booknum").html("0");
		$("#mainCol .dinggou table tfoot .price").html("0.00");
		$("#mainCol .dinggou table tfoot input").attr("disabled","disabled");
	}else{
		var trObj=type.parents("tr");
		$("select",trObj).removeAttr("disabled")
		$(".taoshu",trObj).removeAttr("disabled")
		
		priceCalculate(trObj);
		
		var typeValue=type.val()-0;
		var typeText="";
		if (typeValue==1){
			typeText="全年";
		}else if (typeValue==2){
			typeText="半年";
		}else if (typeValue==3){
			typeText="本期";
		}
		$("#mainCol .dinggou table tfoot .type").html(typeText);
		$("#mainCol .dinggou table tfoot input").removeAttr("disabled");
	}
}
function initPrice2(){
	$("#mainCol .dinggou table select").attr("disabled","disabled");
	$("#mainCol .dinggou table .taoshu").attr("disabled","disabled");
	
	var type = $("#mainCol .dinggou table input.type:checked");
	if (type.length==0){
		$("#mainCol .dinggou table tfoot .booknum").html("0");
		$("#mainCol .dinggou table tfoot .price").html("0.00");
	}else{
		var trObj=type.parents("tr");
		$("select",trObj).removeAttr("disabled")
		$(".taoshu",trObj).removeAttr("disabled")
		
		priceCalculate(trObj);
		
		var typeValue=type.val()-0;
		var typeText="";
		if (typeValue==1){
			typeText="全年";
		}else if (typeValue==2){
			typeText="半年";
		}else if (typeValue==3){
			typeText="本期";
		}
		$("#mainCol .dinggou table tfoot .type").html(typeText);
		$("#mainCol .dinggou table tfoot input").removeAttr("disabled");
	}
}

function priceCalculate(trObj){
	var taoshuObj=$("input.taoshu",trObj);
	
	isNum(taoshuObj.get(0));
		
	if ($(".type",trObj).get(0).checked){
		var set = taoshuObj.get(0).value;
		var num = $(".booknum",trObj).html();
		var booknum = set * num;
		
		var setPrice = $(".price",trObj).html();
		var price = set * setPrice;
		
		$("#mainCol .dinggou table tfoot .booknum").html(booknum);
		$("#mainCol .dinggou table tfoot .price").html(changeTwoDecimal_f(price));
	}
}

function initSubCol(){
	$("#subCol .quick .bookname").mouseover(function(){
		var dd = $(this).parents("dd");
		var ddparent = $(this).parents("dl");
		$("dd",ddparent).removeClass("curr");
		$(".xiangxi",ddparent).hide();
		dd.addClass("curr");
		$(".xiangxi",dd).show();		
	});
}


var currentRandomTime = 60;
function initMobile(ckPhone,ckTime){
	if (ckPhone != null && ckPhone != ""){
		var phone = document.getElementsByName("u_phone");
		phone.item(0).value = ckPhone;
	}
	
	if (ckTime != null && ckTime != ""){
		var time = new Date();
		var time2 = new Date(Date.parse(ckTime.replace(/-/g,   "/")));
		
		if (time2 !=null){
			currentRandomTime = currentRandomTime - Math.round((time-time2)/1000,0);
			
			if (currentRandomTime>0){
				window.setTimeout(mobileRandomTimes,1000);
			}
		}
	}
}

function mobileRandomTimes(){
	currentRandomTime--;
	var sendRandom = document.getElementsByName("sendrandom");
	if (currentRandomTime>0){
		sendRandom.item(0).value = "等待" + currentRandomTime + "秒后重新发送验证码";
		sendRandom.item(0).disabled = true;
		mobileTimeoutID = window.setTimeout(mobileRandomTimes,1000);
	}else{
		sendRandom.item(0).value = "发送验证码";
		sendRandom.item(0).disabled = false;
	}
}
function initFold(){
	$(".fold[hidd=false]").each(function(index, element) {
        var group = this.attributes.group.value;
		$(".leaf[group="+group+"]").show();
		if (this.tagName=="INPUT"){
			this.checked=true;
		}else{
			this.innerHTML = this.innerHTML.replace("[+]","[-]");
		}
    });
	
	$(".fold").bind("click",function(){
		var group = this.attributes.group.value;
		var hidd = this.attributes.hidd.value;
		if (hidd=="true"){
			$(".leaf[group="+group+"]").show();
			this.attributes.hidd.value = "false";
			if (this.innerHTML){
				this.innerHTML = this.innerHTML.replace("[+]","[-]");
			}
		}else{
			$(".leaf[group="+group+"]").hide();
			this.attributes.hidd.value = "true";
			if (this.innerHTML){
				this.innerHTML = this.innerHTML.replace("[-]","[+]");
			}
		}		
	});
}

function initDingDan2(){
	$("#mainCol table tr .taoshu").keyup(function(e){
		if(isNum(e.target)){
			if(e.target.value==0)e.target.value=1;
			
			dingDan2Chanage(e.target);
		}
	});
	
	$("#mainCol table tr li.up").click(function(e){
		var taoshu=$(".taoshu",$(e.target).parents(".numbox")).get(0);

		taoshu.value=taoshu.value-0+1;
		dingDan2Chanage(taoshu);
	});
	$("#mainCol table tr li.down").click(function(e){
		var taoshu=$(".taoshu",$(e.target).parents(".numbox")).get(0);
		
		if (taoshu.value-0>1){
			taoshu.value=taoshu.value-1;
			dingDan2Chanage(taoshu);
		}
	});
	$("#mainCol table tr input.enabled").click(function(e){
		var taoshu=$(".taoshu",$(e.target).parents("tr")).get(0);
		dingDan2Chanage(taoshu);
	});
}

function dingDan2Chanage(e){
	var taoshu=e.value;
	var price=$(".price .singleprice",$(e).parents("tr")).html();
	
	$(".price .countprice",$(e).parents("tr")).html(changeTwoDecimal_f(taoshu*price));
	
	var heji=0;
	
	$("#mainCol table tr input.enabled:checked").each(function(){
		heji=heji+($(".price .countprice",$(this).parents("tr")).html()-0);
	});
	
	$("#mainCol .dingdanbottom .heji").html(changeTwoDecimal_f(heji));
}
function initVideo(){
	$(".bbscon .singbbs .huifu").click(function(){
		var hidd = this.attributes.hidd.value;
		if (hidd=="false"){
			$(".huifubbs",$(this).parents("dd")).hide();
			this.innerHTML = this.innerHTML.replace("-","+");
			this.attributes.hidd.value = "true";
		}else{
			$(".huifubbs",$(this).parents("dd")).show();
			this.innerHTML = this.innerHTML.replace("+","-");
			this.attributes.hidd.value = "false";
		}
	});
	
	$(".infocontent textarea").keyup(function(){
		var len = this.value.length;
		var con = $(".xian span.con",$(this).parents("ul")).html()-0;
		if (len<=con){
			$(".xian span.cur",$(this).parents("ul")).html(this.value.length);
		}else{
			$(".xian span.cur",$(this).parents("ul")).html(this.value.length);
			this.value = this.value.substring(0,con);
		}
	});
	
	$("#mainCol .bookinfo .curvideotitle ul li").mouseover(function(){
		$(this).parent().css("background-image","url(images/"+this.className+".png)");
		$("#mainCol .bookinfo .curvideotitle li .starnum").html(this.className.replace("star",""));
	});
	
	$("#mainCol .bookinfo .curvideotitle li input").hover(function(){
		$("#mainCol .bookinfo .pingfeninfo").show();
	},function(){
		$("#mainCol .bookinfo .pingfeninfo").hide();
	});
}

function initHelp(){
	$(".helpsearch .searchtext").focus(function(){
		if (this.value=="请输入问题关键字"){
			this.value="";
		}
	});
	
	$(".helpsearch .searchtext").blur(function(){
		if (this.value==""){
			this.value="请输入问题关键字";
		}
	});
	
	$("#subCol dd.question a").hover(function(){
		this.parentNode.className="hover";
	},function(){
		this.parentNode.className="";
	});
}

function initXiLie(){
	$(".newqikancon li .hoverbg").fadeOut();
	
	$(".newqikancon li").hover(function(){
		
		$(".bg",this).fadeOut("100");
		$(".hoverbg",this).fadeIn("100");
		
		$(".baoyou",this).show();
		$(".normal",this).hide();
		$(".hover",this).show();
	},function(){
		$(".hover a",this).removeClass("cur");
		
		$(".hoverbg",this).fadeOut("100");
		$(".bg",this).fadeIn("100");		
		
		$(".baoyou",this).hide();
		$(".normal",this).show();
		$(".hover",this).hide();
		
		$("img",this).hide();
		$("img:first",this).show();
	});
	
	$(".newqikancon .hover .taozhuang a").hover(function(){
		var num = this.innerHTML;
		$("a",$(this).parent()).removeClass("cur");
		this.className="cur";
		$("img",$(this).parents("li")).hide();
		$("img",$(this).parents("li")).get(num).style.display="block";
	},function(){
		$("img",$(this).parents("li")).hide();
		$("img:first",$(this).parents("li")).show();
	});
}

function initScroll(){
	var obj = $(".qianggoucon li");
	var num = obj.length;
	$(".qianggoucon ul").css("width",(num*410)+"px");
	
	$(".qianggoucon .left").click(function(){
		if (notClick){
			notClick=false;
			leftScroll();
		}
	});
	
	$(".qianggoucon .right").click(function(){
		if (notClick){
			notClick=false;
			rightScroll();
		};
	});
	
	$(".qianggoucon li").hover(function(){
		window.clearTimeout(scrollTimeoutID);
	},function(){
		scrollTimeoutID = window.setTimeout(leftScroll,5000);
	});
	
	scrollTimeoutID = window.setTimeout(leftScroll,5000);
}
function leftScroll(){
	window.clearTimeout(scrollTimeoutID);
	var ul = $(".qianggoucon ul");
	
	ul.animate({marginLeft:"-410px"},"slow","",function(){
		$(".qianggoucon li:first").appendTo(ul);
		$(".qianggoucon ul").css("margin-left","0");
		notClick=true;
	});		
	
	scrollTimeoutID = window.setTimeout(leftScroll,5000);
}
function rightScroll(){
	window.clearTimeout(scrollTimeoutID);
	var ul = $(".qianggoucon ul");
	
	$(".qianggoucon li:last").prependTo(ul);
	$(".qianggoucon ul").css("margin-left","-410px");
	
	ul.animate({marginLeft:"0"},"slow","",function(){
		notClick=true;
	});	
	
	scrollTimeoutID = window.setTimeout(leftScroll,5000);
}

function msgBox(title,text){
	var msg = $("div.messagebox");
	if(msg.length==0){
		$("body").append("<div class='messagebox'><div class='title'><a href='javascript:;' onclick='closeMsgBox(\"messagebox\")' class='close'></a><span>"+title+"</span></div><p>"+text+"</p></div>");
	}else{
		$("p",msg).html(text);
		$(".title span",msg).html(title);
	}
	center($("div.messagebox"));
	
	$("div.messagebox").show();
}
function msgBox2(title,text){
	var msg = $("div.messagebox2");
	if(msg.length==0){
		$("body").append(
			"<div class='messagebox2'><div class='indexpop'><div class='box'><div class='title'><a href='javascript:;' onclick='closeMsgBox2()' class='close'>&times;</a><span>"+title+"</span></div><p>"+text+"</p></div><div class='wrapshadow'></div></div></div>"
		);
	}else{
		$("p",msg).html(text);
		$(".title span",msg).html(title);
	}
	
	$("div.messagebox2").show(0,function(){
		if(!$.support.style){
			var width = $(".messagebox2 p").width()-0+40;
			$(".messagebox2 .box").width((width-0)+"px");
			$(".messagebox2 .indexpop").width((width-0+10)+"px");
			$(".messagebox2 .wrapshadow").width((width-0+10)+"px");
		}
	});
	
	
	var obj=$("div.messagebox2");
	
	var screenWidth = $(window).width();
	var screenHeight = $(window).height();
	var scrolltop = $(document).scrollTop();
	var objLeft = (screenWidth - obj.width())/2 ;
	var objTop = scrolltop - obj.height();
	var objTopBack = scrolltop - obj.height();
	var height = (screenHeight - obj.height())/2 + scrolltop;
	var cha = height-objTop;
	obj.css({left: objLeft + 'px', top: objTop + 'px'});

	function toCenter() {
		objTop = objTop + cha/10;
		
		if (objTop<=height){
			obj.css({left: objLeft + 'px', top: objTop + 'px'});
			window.setTimeout(toCenter,50);
		}else{
			obj.css({left: objLeft + 'px', top: height + 'px'});
			objTop = objTopBack;
			window.setTimeout(toTop,1000);
		}
	}
	
	function toTop() {
		height = height - cha/10;
		
		if (height>=objTop){
			obj.css({left: objLeft + 'px', top: height + 'px'});
			window.setTimeout(toTop,50);
		}else{
			obj.css({left: objLeft + 'px', top: objTop + 'px'});
			obj.hide();
		}		
	}
	
	toCenter()
}
function msgBox3(href){
	var msg = $("div.messagebox3");
	if(msg.length==0){
		$("body").append(
			"<div class='messagebox3'><div class='indexpop'><div class='box'><div class='title'><span>提示</span></div><p>订单已经提交成功，请尽快付款</p><div class='button'><a class='go' href='submitOrder!reSubOrder?id="+href+"' target=\"_blank\">去支付</a><a href='javascript:;' onclick='window.location.href(\"MyOrder!myOrder.action?scan_type=all\")'>已完成支付</a></div><div class='tip'><a href='http://shop.dfww.com.cn/dialog.htm'>支付遇到问题？</a></div>	</div><div class='wrapshadow'></div></div></div>"
		);
	}else{
		$("a.go",msg).attr("href",href);
	}
	
	center($("div.messagebox3"));
	
	$("div.messagebox3").show();
}
function closeMsgBox(objName){
	$("div.messagebox").hide();
	$(window).unbind("resize");
	$(window).unbind("scroll");
}
function closeMsgBox2(){
	$("div.messagebox2").hide();
	$(window).unbind("resize");
	$(window).unbind("scroll");
}
function closeMsgBox3(){
	$("div.messagebox3").hide();
	$(window).unbind("resize");
	$(window).unbind("scroll");
}
function center(obj) {
	var screenWidth = $(window).width(), screenHeight = $(window).height(); //当前浏览器窗口的 宽高
	var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
	var objLeft = (screenWidth - obj.width())/2 ;
	var objTop = (screenHeight - obj.height())/2 + scrolltop;
	obj.css({left: objLeft + 'px', top: objTop + 'px'});	

	//浏览器窗口大小改变时
	$(window).resize(function() {
		screenWidth = $(window).width();
		screenHeight = $(window).height();
		scrolltop = $(document).scrollTop();
		objLeft = (screenWidth - obj.width())/2 ;
		objTop = (screenHeight - obj.height())/2 + scrolltop;
		obj.css({left: objLeft + 'px', top: objTop + 'px'});
	});
	
	//浏览器有滚动条时的操作、
	$(window).scroll(function() {
		screenWidth = $(window).width();
		screenHeight = $(window).height();
		scrolltop = $(document).scrollTop();
		objLeft = (screenWidth - obj.width())/2 ;
		objTop = (screenHeight - obj.height())/2 + scrolltop;
		obj.css({left: objLeft + 'px', top: objTop + 'px'});
	});
}
function zuhescroll(isClick){
	var list = $(".zuhe .list .on");
	if(list.next().get(0).className!="last"){
		list.next().addClass("on");
		list.removeClass("on");
	}else{
		$(".zuhe .list .num:first").addClass("on");
		list.removeClass("on");
	}
	$(".zuhe .zuhebody ul:first").animate({marginTop:"-160px"},"slow","",function(){
		$(".zuhe .zuhebody ul:first").appendTo($(".zuhe .zuhebody"));
		$(".zuhe .zuhebody ul").css("margin-top",0);
		if(!isClick){
			zuheID = window.setTimeout(zuhescroll,5000);
		}
		notClick = true;
	});	
}
function zuhescrollLeft(){
	var list = $(".zuhe .list .on");
	if(list.prev().get(0).className!="first"){
		list.prev().addClass("on");
		list.removeClass("on");
	}else{
		$(".zuhe .list .num:last").addClass("on");
		list.removeClass("on");
	}
	$(".zuhe .zuhebody ul:last").prependTo($(".zuhe .zuhebody")).css("margin-top","-160px");
	
	$(".zuhe .zuhebody ul:first").animate({marginTop:"0"},"slow","",function(){
		notClick = true;
	});	
}
function zuheTo(obj){
	$(".zuhe .list .on").removeClass("on");
	$(obj).addClass("on");
	
	var num=obj.innerHTML-0;
	var ulList=new Array();
	var i=0;

	$(".zuhe .zuhebody ul").each(function(index, element) {
		if(this.attributes.lid.value-0!=num){
			ulList[i]=$(this);
			i++;
		}else{
			return false;
		}
  });
	for(var j=0;j<ulList.length;j++){
		ulList[j].appendTo($(".zuhe .zuhebody"));
	}
	
	notClick=true;
}
function zuheShowAuto(){
	var obj = $(".zuhe .zuhebody ul.on").next().get(0);
	if (obj.nodeName=="DIV"){
		obj = $(".zuhe .zuhebody ul:first").get(0);
	}
	zuheShow(obj);
}
function zuheShow(obj){	
	var lid=obj.attributes.lid.value;
	$(".zuhe .list a.on").removeClass("on");
	$(".zuhe .list a.num").get(lid-1).className="num on";
		
	$(".zuhe .zuhebody ul.on").fadeOut("slow",function(){
		this.className="";
		$(obj).fadeIn("slow",function(){
			notClick=true;
			this.className="on";
			
			zuheID = window.setTimeout(zuheShowAuto,5000);
		});
	});	
}

var dituxml=null;
function initZuHe(){
	zuheID = window.setTimeout(zuheShowAuto,5000);
	$(".zuhe .zuhebody").hover(function(){
		window.clearTimeout(zuheID);
	},function(){
		window.clearTimeout(zuheID);
		zuheID = window.setTimeout(zuheShowAuto,5000);
	});
	
	$(".zuhe .list a").mouseover(function(){
		window.clearTimeout(zuheID);
	});
	
	$("table input.gouwuche").click(function(){
		
		var catid = $(".dinggou table .type").attr("catid");
		var time = $(".dinggou table select").val(); 
		var num = $(".dinggou table input.taoshu").val();
		var order_type = $(".dinggou table input.order_type").val();
		
		var img = $(".bookbuy .showbook img:first").attr("src");
		var name = $(".dinggou .dinggoutitle strong").text();
		var price = $(".dinggou table .price").html();
		
		getGouwuche(catid,time,num,order_type,img,name,price,this);
	});
	
	$(".v-list input.gouwuche").click(function(){		
		var year = new Date().getFullYear();
		var month = new Date().getMonth()+1;
		
		var li = $(this).parents("li");
		var catid = $("input.catid",li).val();
		var time = year + "-" + month; 
		var num = 1;
		var order_type = $("input.order_type",li).val();
		
		var img = $(".h-list li img:first").attr("src");
		var name = $("h3 a",li).text();
		var price = $(".shoujia span",li).html().replace("￥","");
		
		getGouwuche(catid,time,num,order_type,img,name,price,this);
	});
	
	$("table input.goumai").click(function(){
		
		var catid = $(".dinggou table .type").attr("catid");
		var time = $(".dinggou table select").val(); 
		var num = $(".dinggou table input.taoshu").val();
		var order_type = $(".dinggou table input.order_type").val();
		
		var img = $(".bookbuy .showbook img:first").attr("src");
		var name = $(".dinggou .dinggoutitle strong").text();
		var price = $(".dinggou table .price").html();
		
		getGouwucheGo(catid,time,num,order_type,img,name,price);
	});
	
	$(".v-list input.goumai").click(function(){		
		var year = new Date().getFullYear();
		var month = new Date().getMonth()+1;
		
		var li = $(this).parents("li");
		var catid = $("input.catid",li).val();
		var time = year + "-" + month; 
		var num = 1;
		var order_type = $("input.order_type",li).val();
		
		var img = $(".h-list li img:first").attr("src");
		var name = $("h3 a",li).text();
		var price = $(".shoujia span",li).html().replace("￥","");
		
		getGouwucheGo(catid,time,num,order_type,img,name,price);
	});
	
	$(".zuhe .list a.num").click(function(){
		if(notClick){
			notClick=false;
			window.clearTimeout(zuheID);
			
			zuheShow($(".zuhe .zuhebody ul").get(this.innerHTML-1));
		}
	});
	$(".zuhe .list a.first").click(function(){
		if(notClick){
			notClick=false;
			window.clearTimeout(zuheID);
			obj = $(".zuhe .zuhebody ul.on").prev().get(0);
			if (!obj){
				obj = $(".zuhe .zuhebody ul:last").get(0);
			}
			zuheShow(obj);
		}
	});
	$(".zuhe .list a.last").click(function(){
		if(notClick){
			notClick=false;
			window.clearTimeout(zuheID);
			zuheShowAuto();
		}
	});
	
	$(".newdinggou span.diqu").click(function(e){
		$(".dinggou table select").hide();
		var off = $(this).offset();
		$("#expressregion").css("top",(off.top-0+20)+"px").css("left",off.left+"px").show();
		 e.stopPropagation();
	});
	$(document).click(function(e){
		$("#expressregion").hide();
		 e.stopPropagation();		
	});
	$("div.expressregion a").click(function(){
		$("span.diqu").html(this.innerHTML);
		$("#expressregion").hide();
		$(".dinggou table select").show();
		postalOpar(dituxml,this.innerHTML);
	});
		
	$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js',function(){ 
		$(".newdinggou span.diqu").html(remote_ip_info.province);
		getPostal(remote_ip_info.province);
	}) 
}
function getGouwuche(catid,time,num,order_type,img,name,price,btnObj){
	//cart!addCart.action
	$.post("cart!addCart.action",{book_id:catid,start_time:time,order_num:num,type:order_type},function(data){
		
		btnObj = $(btnObj);
		var pos = btnObj.offset();
		$("div.gouwuchebox").css("top",(pos.top+btnObj.height()/2)+"px").css("left",(pos.left+btnObj.width()/2)+"px").html(data).show();;
		
		var listNum=$(".cartlist .item").length;
		if(listNum==0){
			$(".cartlist .null").hide();
			$(".cartlist .count").show();
		}
		
		var cart = '<li class="item">'
    cart +='<a class="img" href="javascript:;"><img src="'+img+'" width="45" height="45"></a>';
    cart +='<span class="title"><a href="javascript:;">'+name+'</a></span>';
    cart +='<span class="price"><strong>￥'+price+'</strong>元</span>';
    cart +='<a class="del" key="0" href="javascript:;">移除</a>';
    cart +='</li>';		
		
		$(".cartlist ul").append(cart);
		
		listNum++;
		
		$(".menu2 .m3 span").html(listNum);
		$(".cartlist .count strong").html(listNum);
		
		$("#innerHeader .cartlist .del").unbind("click").click(function(e){
			var catID = this.parentNode.attributes.catid.value;
			removeOrder(catID,1);
		});
		
	},"text");
}
function getGouwucheGo(catid,time,num,order_type,img,name,price){
	//cart!addCart.action
	$.post("cart!addCart.action",{book_id:catid,start_time:time,order_num:num,type:order_type},function(data){
		
		var listNum=$(".cartlist .item").length;
		if(listNum==0){
			$(".cartlist .null").hide();
			$(".cartlist .count").show();
		}
		
		var cart = '<li class="item">'
    cart +='<a class="img" href="javascript:;"><img src="'+img+'" width="45" height="45"></a>';
    cart +='<span class="title"><a href="javascript:;">'+name+'</a></span>';
    cart +='<span class="price"><strong>￥'+price+'</strong>元</span>';
    cart +='<a class="del" key="0" href="javascript:;">移除</a>';
    cart +='</li>';		
		
		$(".cartlist ul").append(cart);
		
		listNum++;
		
		$(".menu2 .m3 span").html(listNum);
		$(".cartlist .count strong").html(listNum);
		
		$("#innerHeader .cartlist .del").unbind("click").click(function(e){
			var catID = this.parentNode.attributes.catid.value;
			removeOrder(catID,1);
		});
		
		window.location.href="cart!myCart.action";
	},"text");
}
function getPostal(province){
	//Xml!postageXML.action
	$.post("Xml!postageXML.action",{},function(xml){
		dituxml=xml;
		postalOpar(xml,province);
	},"xml");
}
function postalOpar(xml,province){
	$(xml).find("postage").each(function(index,element){
		var diqu=$(this).find("province").text();
		if (province==diqu){
			var kuaidi=$(this).find("courier").text();
			var youfei=$(this).find("postal").text();
			$(".newdinggou span.kuaidi").html(changeTwoDecimal_f(kuaidi));
			$(".newdinggou span.pinyou").html(changeTwoDecimal_f(youfei));
			return false;
		}
	});
}
function resetCenter() {
	obj = $(".imgshow");
	var screenWidth = $(window).width(), screenHeight = $(window).height(); //当前浏览器窗口的 宽高
	var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
	var scrollleft = $(document).scrollLeft();//获取当前窗口距离页面顶部高度
	var objLeft = (screenWidth - obj.width())/2 + scrollleft;
	var objTop = (screenHeight - obj.height())/2 + scrolltop;
	obj.css({left: objLeft + 'px', top: objTop + 'px'});	
}

var overImg=false;
var left=true;
function initImg(){
	$(".imglist .imgbox img").click(bindImg);
	
	$(".imgshow img").mouseover(function(e){
		overImg=true;
	}).mousemove(function(e) {
    if(overImg){
			var width=this.width/2;
			var cur=e.clientX-$(".imgshow").position().left-49;
			if(width>cur){
				$(this).css("cursor","url(images/prev.cur), w-resize").attr("title","上一张");
				left=true;
			}else{
				$(this).css("cursor","url(images/next.cur), e-resize").attr("title","下一张");
				left=false;
			}
		}
  }).mouseout(function(e) {
    overImg=false;
  }).click(function(e) {
		var index=0;
		var src=this.src;
		var imgList=$(".imglist .imgbox img");
    imgList.each(function(){
			if (this.src==src){
				return false;
			}
			index++;
		});
		if (left && index>0){
			imgList[index-1].click();
		}else if(!left && index<imgList.length-1){
			imgList[index+1].click();
		}
  });
}
function bindImg(){
	var img = new Image();
	img.onload = function(){
		var height = $(window).height()-90;
		var width = $(window).width()-98;
		var imgHeight = img.height;
		var imgWidth = img.width;
		if (height<imgHeight){
			imgWidth = height/imgHeight * imgWidth;
			imgHeight = height;
		}
		if (width<imgWidth){
			imgHeight = width/imgWidth * imgHeight;
			imgWidth = width;
		}
		$(".imgshow img").attr("src",img.src).attr("width",imgWidth).attr("height",imgHeight);
		$(".divouter").show();
		$(".imgshow").show(function(){
			$(this).css("width",(imgWidth+49*2)+"px")
			window.setTimeout(resetCenter,50);
		});
	};
	img.src = this.src;
}

function newOrder(){
	$(".orderdata li.up").click(function(e) {
		var tr = $(this).parents("tr");
    var input = $(".numbercontrol input",tr);
		input.val(input.val()-0+1);
		
		var single = $(".singlepoint",tr).html()-0;
		$(".countpoint",tr).html((single*(input.val()-0)));
			
		newOrderChanage($(input));
		
		var catid = tr.attr("catid");
		$.get("cart!editCart.action",{id:catid,edit_type:"up"});
  });
	
	$(".orderdata li.down").click(function(e) {
		var tr = $(this).parents("tr");
    var input = $(".numbercontrol input",tr);
		var val = input.val()-0;
		if(val>1){
			input.val(val-1);
			
			var single = $(".singlepoint",tr).html()-0;
			$(".countpoint",tr).html((single*(input.val()-0)));
		
			newOrderChanage($(input));
			
			var catid = tr.attr("catid");
			$.post("cart!editCart.action",{id:catid,edit_type:"down"});
		}
  });
	$(".orderdata .numbercontrol input").keyup(function(e) {
		var tr = $(this).parents("tr");
		
    if(isNum(e.target)){
			if(e.target.value==0)e.target.value=1;
		}
		
		var single = $(".singlepoint",tr).html()-0;
		$(".countpoint",tr).html((single*(this.value-0)));
		
		newOrderChanage($(this));
		
		var catid = tr.attr("catid");
		$.post("cart!editCart.action",{id:catid,edit_type:"input",edit_num:e.target.value});
  });
	
	$(".orderdata .act a").click(function(e){
		var tr = $(this).parents("tr");
		var catid = tr.attr("catid");
		removeOrder(catid,0);
	});
	
	newOrderChanage(null);
	getDefault();
	
	if($("table.orderdata tbody tr").length==0){
		$(".ordertongji .red").hide();
	}
	
	$(".cartlist .item .del").unbind("click").click(function(){
		var catid = $(this).parent().attr("catid");
		removeOrder(catid,0);
	});
}
function getDefault(){
	$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js',function(){ 
		var province = remote_ip_info.province;
		//CartNext!findPostageByWords.action
		$.post("CartNext!findPostageByWords.action",{province:province},function(xml){
			var province = $(xml).find("province").text();
			var prior_charges = $(xml).find("prior_charges").text();
			
			var huodongStr = "";
			if (prior_charges==""){
				huodongStr = "您的收货地是 <span>"+province+"</span> 没有包邮活动";
			}else{
				huodongStr = "您的收货地是 <span>"+province+"</span> 期刊订单满 <span>"+prior_charges+"</span> 元包全年12期全快递";
			}
			$(".category tfoot .huodong").html(huodongStr);
		},"xml");
	}) 
}
function removeOrder(catid,type){
	$.post("addgouwuche.jsp",{book_id:catid},function(data){
		if (type==0){
			$("table.orderdata tbody tr[catid="+catid+"]").remove();
			newOrderChanage(null);
			
			if($("table.orderdata tbody tr").length==0){
				$(".ordertongji .red").hide();
			}
		}
		removeCart($("#innerHeader .cartlist li[catid="+catid+"]"));
	})
}
function newOrderChanage(inputObj){
	if(inputObj != null){
		var trObj = inputObj.parents("tr");
		var taoshuo = inputObj.val()-0;
		var emObj = $(".price em",trObj);
		var xiaoji = 0;
		
		if (emObj.length>0){
			xiaoji = taoshuo * (emObj.text().replace("￥","") - 0)
		}else{
			var spanObj = $(".price span",trObj);
			xiaoji = taoshuo * (spanObj.text().replace("￥","") - 0)
		}
		
		$(".xiaoji",trObj).html("￥"+changeTwoDecimal_f(xiaoji));
	}
	var yuanshi=0;
	
	$(".orderdata tbody tr").each(function(){
		if(inputObj == null){
			var trObj = $(this);
			var taoshuo = $(".numbercontrol input",this).val()-0;
			var emObj = $(".price em",trObj);
			var xiaoji = 0;
		
			if (emObj.length>0){
				xiaoji = taoshuo * (emObj.text().replace("￥","") - 0)
			}else{
				var spanObj = $(".price span",trObj);
				xiaoji = taoshuo * (spanObj.text().replace("￥","") - 0)
			}
			
			$(".xiaoji",trObj).html("￥"+changeTwoDecimal_f(xiaoji));
		}
		
		var curPrice=$(".xiaoji",this).html().replace("￥","")-0;
		yuanshi+=curPrice;
	});
	
	$(".ordertongji .jisuan span").html(changeTwoDecimal_f(yuanshi));
	
}

function navigation(){
	$(".yearlist .year li").click(function(e){	
		$(".yearlist .year li.on").removeClass("on");
		this.className="on";
	});
	
	$(".yearlist .month li").click(function(e){
		var year = $(".yearlist .year li.on").val();
		var month = this.value;
		
		$(".yearlist .month li.on").removeClass("on");
		this.className="on";
		
		getNavigation(year,month,0);
	});
	
	var year = new Date().getFullYear();
	var month = new Date().getMonth()+1;
	
	$(".yearlist .month li").get(month-1).className="on";
	
	getNavigation(year,month,1);
}
function getNavigation(year,month,type){
	//Xml!navigationXML.action
	if(category_id==null){
		category="100101";
	}
	$.ajax({
		url:"Xml!navigationXML.action",
		dataType:"xml",
		data:{navigation_year:year,navigation_month:month,navigation_category:category_id},
		success: function(xml){
			var books = $(xml).find("books");
			if (books.length==0 && type == 1){
				if (month==1){
					year=year-1;
					month=12;
				}else{
					month=month-1;
				}
				getNavigation(year,month,type);
			}else{
				var html = "";
				books.each(function(){
					var img=$(this).find("img").text();
					var title=$(this).find("book_name").text();
					var book_id=$(this).find("book_id").text();
					html+="<li>";
					html+='<a class="img" href="periodical.action?id='+book_id+'"><img src="'+img+'" width="115" height="136" /></a>';
					html+='<a class="title" href="periodical.action?id='+book_id+'">'+title+'</a>';
					html+="</li>";
				});
				$(".yearlist .list").html(html);
			}
		},
		error: function(jqXHR, textStatus, errorThrown){
			if (month==1){
				year=year-1;
				month=12;
			}else{
				month=month-1;
			}
			getNavigation(year,month,type);
		}
	});
}

function newOrder2(){
	$(".addrlist li").click(function(e) {
		$(".addrlist li").removeClass("cur");
    this.className="cur";
		
		$("#select_addr_id").val(this.attributes.aid.value);
		
		getPostage();
  });
	$(".addrleaf .tip .close").click(function(e){
		$(".addrleaf .tip").hide();
	});
	$(".orderdata tfoot .postagetype").change(function(e) {
		jisuanOrder();
  });
	$(".jiesuaninfo input.qinyou").focus(function(){
		if (this.value=="输入亲友的帐号"){
			this.value="";
		}
	}).blur(function(){
		if (this.value==""){
			this.value="输入亲友的帐号";
		}
	});
	$(".addform .button").click(addAddress);
	
	$(".jiesuaninfo input.jifen").keyup(function(){
		var maxJifen = $(".jiesuaninfo span.curjifen").html()-0;
		
		var reg=/^(0|([1-9]\d*))$/;
		if (!reg.test(this.value)){
			this.value = 0;
		}else if(this.value-0<0){
			this.value=0;			
		}else if(this.value-0>maxJifen){
			this.value=maxJifen;
		}
	});
	
	$(".jiesuaninfo input.usexianjin").click(function(){
		var u_referrer = $(this).prev().val();
		if (u_referrer !=""){
			//CartNext!ckU_referrer.action
			$.post("CartNext!ckU_referrer.action",{u_referrer:u_referrer},function(xml){
				var result = $(xml).find("result").text();
				var msg = $(xml).find("msg").text();
				if (result == "1"){
					$(".jiesuaninfo .xianjintip").addClass("chenggong");
				}else{
					$(".jiesuaninfo .xianjintip").removeClass("chenggong");
				}
				$(".jiesuaninfo .xianjintip").html(msg).show();
			},"xml");
		}
	});
	
	$(".jiesuaninfo input.usejifen").click(function(){
		var use_integral = $(".jiesuaninfo input.jifen").val()-0;
		if (use_integral>0){
			//CartNext!useIntegral.action
			$.post("CartNext!useIntegral.action",{use_integral:use_integral},function(xml){
				var result = $(xml).find("result").text();
				var msg = $(xml).find("msg").text();
				if (result=="1"){
					//CartNext!showUserIntegral.action
					$.post("CartNext!showUserIntegral.action",{},function(xml){
						var u_integral = $(xml).find("u_integral").text();
						$(".jiesuaninfo span.curjifen").html(u_integral);
						
					},"xml");
				}
				
				$(".jiesuaninfo input.jifen").hide();
				$(".jiesuaninfo input.usejifen").hide();
				$(".jiesuaninfo input.canceljifen").show();

				$(".jiesuaninfo label.tip2").html(msg).show();
				
				jisuanOrder();
			},"xml");
		}
	});
	
	//撤销积分抵现
	$(".jiesuaninfo input.canceljifen").click(function(){
		//CartNext!cancel_use_integral.action
		$.post("CartNext!cancel_use_integral.action",function(xml){
			var result = $(xml).find("result").text();
			var msg = $(xml).find("msg").text();
			if (result=="1"){
				//CartNext!showUserIntegral.action
				$.post("CartNext!showUserIntegral.action",{},function(xml){
					var u_integral = $(xml).find("u_integral").text();
					$(".jiesuaninfo span.curjifen").html(u_integral);
					
				},"xml");
			}
			
			$(".jiesuaninfo label.use_integral_refresh").hide();
			$(".jiesuaninfo input.jifen").show();
			$(".jiesuaninfo input.usejifen").show();
			$(".jiesuaninfo input.canceljifen").hide();

			$(".jiesuaninfo label.tip2").html(msg).show();
			
			jisuanOrder();
		},"xml");
	});
	
	$(".jiesuaninfo .qinyoubtn").click(function(){
		var u_referrer = $(".jiesuaninfo .qinyou").val();
		if (u_referrer !=""){
			//CartNext!ckU_referrer.action
			$.post("CartNext!ckU_referrer.action",{u_referrer:u_referrer},function(xml){
				var result = $(xml).find("result").text();
				var msg = $(xml).find("msg").text();
				if (result == "1"){
					$(".jiesuaninfo .qinyoutip").addClass("chenggong");
				}else{
					$(".jiesuaninfo .qinyoutip").removeClass("chenggong");
				}
				$(".jiesuaninfo .qinyoutip").html(msg).show();
			},"xml");
		}
	});
	
	$(".jiesuaninfo .diyongjuanleaf input").click(function(){
		if (this.checked){
			$(".jiesuaninfo .diyongjuanleaf input").removeAttr("checked");
			this.checked=true;
		}
		jisuanOrder();
	});
	
	$(".jiesuaninfo .zongji a.red").click(sendOrder);

	jisuanOrder();
	
	var addrNum = $(".addrlist li").length;
	if(addrNum==0){
		getDefault();
	}else{
		getPostage();
	}
	if(addrNum==5){
		$(".manageaddr .addform:first").hide();
		$(".manageaddr .addform:last").show();
	}
	
	$("#innerHeader .cartlist .del").hide();
}
function jisuanOrder(){
	var youfei = 0;
	$(".orderdata tfoot .postagetype").each(function(index,element){
		youfei += (element.options[element.selectedIndex].attributes.price.value-0);
		$(element).next().html("￥"+changeTwoDecimal_f(element.options[element.selectedIndex].attributes.price.value));
	});
	
	var jifendixianjin = $("div.jifenleaf .tip2 span.jifendixianjin");
	if (jifendixianjin.length == 0){
		$(".jiesuaninfo .zongji .jifen").html("0.00");
	}else{
		$(".jiesuaninfo .zongji .jifen").html(changeTwoDecimal_f(jifendixianjin.html()));
	}
		
	$(".jiesuaninfo .zongji .yunfei").html(changeTwoDecimal_f(youfei));
	
	var juan = $(".jiesuaninfo .diyongjuanleaf input:checked");
	var youhuiquan = 0;
	if (juan.length==1){
    $("#voucher_id").val(juan.attr("id"));
		youhuiquan = juan.val();
	}else{
		$("#voucher_id").val("");
	}
	$(".jiesuaninfo .zongji .youhuiquan").html(changeTwoDecimal_f(youhuiquan));
	
	var jine = $(".jiesuaninfo .zongji .jine").html().replace("￥","")-0;
	var jifen = $(".jiesuaninfo .zongji .jifen").html().replace("￥","")-0;
	var huiyuan = $(".jiesuaninfo .zongji .huiyuan").html().replace("￥","")-0;
	var zonge=jine+youfei-youhuiquan-jifen-huiyuan;
	
	var zongge = changeTwoDecimal_f(zonge);
	$(".jiesuaninfo .zongji .yingfu em").html("￥"+zongge);
	$("#order_amount").val(zongge);
}

function addAddress(){
	if(checkAddrForm()){
		var addr_consignee = $("#addr_consignee").val();
		var addr_province_code = $("#addr_province").val();
		var addr_province = $("#addr_province option:selected").text();
		var addr_city_code = $("#addr_city").val();
		var addr_city = $("#addr_city option:selected").text();
		var addr_county_code = $("#addr_county").val();
		var addr_county = $("#addr_county option:selected").text();
		var addr_street = $("#addr_street").val();
		var addr_postcode = $("#addr_postcode").val();
		var addr_phone = $("#addr_phone").val();
		var addr_tel = $("#addr_tel").val();
		var addr_default = 0;
		if ($("#addr_default").get(0).checked){
			addr_default = 1;
		}
		if (addr_county_code == "0"){
			addr_county_code = "";
			addr_county = "";
		}
		
		//MyAddress!addAddressNotify.action
		$.post(
			"MyAddress!addAddressNotify.action",
			{
				addr_consignee:addr_consignee,
				addr_province_code:addr_province_code,
				addr_province:addr_province,
				addr_city_code:addr_city_code,
				addr_city:addr_city,
				addr_county_code:addr_county_code,
				addr_county:addr_county,
				addr_street:addr_street,
				addr_postcode:addr_postcode,
				addr_phone:addr_phone,
				addr_tel:addr_tel,
				addr_default:addr_default
			},
			function(xml){
				var result = $(xml).find("result").text();
				if (result=="1"){
					getAddress();
					$(".manageaddr .addaddr .fold").click();;
				}else{
					alert($(xml).find("msg").text());
				}
			},
			"xml"
		);
	}
}

function getAddress(){
	//MyAddress!findAddressNotify.action
	$.post("MyAddress!findAddressNotify.action",{},function(xml){
		var addr = "";
		if ($(xml).find("address").length==5){
			$(".manageaddr .addform:first").hide();
			$(".manageaddr .addform:last").show();
		}
		$(xml).find("address").each(function(){
			var addr_id=$(this).find("addr_id").text();
			var addr_consignee=$(this).find("addr_consignee").text();
			var addr_province=$(this).find("addr_province").text();
			var addr_city=$(this).find("addr_city").text();
			var addr_county=$(this).find("addr_county").text();
			var addr_street=$(this).find("addr_street").text();
			var addr_postcode=$(this).find("addr_postcode").text();
			var addr_phone=$(this).find("addr_phone").text();
			var addr_tel=$(this).find("addr_tel").text();
			var addr_default=$(this).find("addr_default").text();
			
			if (addr_default=="1"){
				addr+='<li class="cur" aid="'+addr_id+'">';
				$("#addr_id").val(addr_id);
			}else{
				addr+='<li aid="'+addr_id+'">'
			}
			addr+='	<p class="city">'+addr_province+'　'+addr_city+'<span>（'+addr_consignee+'收）</span></p>'
			addr+='	<p class="addr">'+addr_county+'　'+addr_street+'<span>('+addr_postcode+')</span><br />'+addr_phone+' '+addr_tel+'</p>'
			addr+='	<div class="selected"></div>'
			addr+='</li>'
		});
		$(".addrlist").html(addr);
		
		$(".addrlist li").click(function(e) {
			$(".addrlist li").removeClass("cur");
			this.className="cur";
			
			$("#select_addr_id").val(this.attributes.aid.value);
			
			getPostage();
		});
		
		getPostage();
	},"xml");
}

function checkAddrForm(){
	if($("#addr_consignee").val() == ""){
		alert("收货人不能为空！");
		return false;
	}
	if($("#addr_province").val() == "0"){
		alert("请选择省份！");
		return false;
	}
	if($("#addr_city").val() == "0"){
		alert("请选择城市！");
		return false;
	}
	if($("#addr_street").val() == ""){
		alert("街道地址不能为空！");
		return false;
	}
	if($("#addr_postcode").val() == ""){
		alert("邮政编码不能为空！");
		return false;
	}else{
		var s = $("#addr_postcode").val();
	  var pattern =/^[0-9]{6}$/;
	  if(!pattern.exec(s))
	  {
			alert('请输入正确的邮政编码');
			return false;
	  }
	}
	
	var phoneStr = $("#addr_phone").val();
	if(phoneStr == "" && $("#addr_tel").val() == ""){
		alert("手机和电话必须填写其中一个！");
		return false;
	}else if ($("#addr_phone").val() != ""){
	  var pattern =/^[0-9]{11}$/;
	  if(!pattern.exec(phoneStr))
	  {
			alert('请输入正确的手机号码');
			return false;
	  }
	}
	
	return true;
}

function getPostage(){
	if ($(".addrlist li.cur").length==0){
		$(".addrlist li:first").addClass("cur");
		$("#select_addr_id").val($(".addrlist li:first").attr("aid"));
	}else{
		$("#select_addr_id").val($(".addrlist li.cur").attr("aid"));
	}
	
	var addr_id = $("#select_addr_id").val();
	
	if (addr_id == ""){
		return false;
	}
	
	//CartNext!findPostage.action
	$.post("CartNext!findPostage.action",{addr_id:addr_id},function(xml){
		var province = $(xml).find("province").text();
		var courier = $(xml).find("courier").text();
		var postal = $(xml).find("postal").text();
		var registered = $(xml).find("registered").text();
		var prior_charges = $(xml).find("prior_charges").text();
		var extra_courier = $(xml).find("extra_courier").text();
		
		var huodongStr = "";
		if (prior_charges==""){
			huodongStr = "您的收货地是 <span>"+province+"</span> 没有包邮活动";
		}else{
			huodongStr = "您的收货地是 <span>"+province+"</span> 期刊订单满 <span>"+prior_charges+"</span> 元包全年12期全快递";
		}
		$(".category tfoot .huodong").html(huodongStr);
		
		var categoryClear = false;
		$(".orderdata tfoot .postagetype").each(function(index,element){
			var type = element.name;
			
			switch(type){
				case "book_send_type":
					if (categoryClear){
						clearPostal(element,1);
					}else{
						bookPostage(courier,postal,registered,prior_charges,extra_courier,element);
					}
					break;
				case "hardcover_send_type":
					if (categoryClear){
						clearPostal(element,1);
					}else{
						categoryClear = promotionPostage(courier,postal,registered,prior_charges,extra_courier,element)
					}
					break;
				case "category_send_type":
					categoryClear = categoryPostage(courier,postal,registered,prior_charges,extra_courier,element)
					break;
			}
		});
		
		jisuanOrder();
		
	},"xml");
}

//单本
function bookPostage(courier,postal,registered,prior_charges,extra_courier,element){
	prior_charges = 200;
	
	var heji = 0;
	var table = $(element).parents("table")		
	$(".xiaoji",table).each(function(index, element) {
		heji += element.innerHTML.replace("￥","")-0;
	});
	
	if (heji>=prior_charges-0){
		clearPostal(element,1);
		
		var promotion = $(".orderdata tfoot .postagetype[name=hardcover_send_type]");
		if(promotion.length>0){
			clearPostal(promotion.get(0),1);
		}
	}else{
		var num = 0;
		$(element).parents("table").find(".num").each(function(index, element) {
			num += (element.innerHTML - 0);
		});
		
		num -= 1;
		num = parseInt(num/2)*5;
		if(parseInt(num/2)*5>10){
			num = 10;
		};	

		if (courier == "0"){
			element.options[0].text = "快递 免运费"
		}else{
			element.options[0].text = "快递 ￥" + ((courier-0)+num);
		}	
		element.options[0].attributes.price.value = ((courier-0)+num);
		
		if ((postal-0) + (registered-0)== 0){
			element.options[1].text = "挂号 免运费"
		}else{
			element.options[1].text = "挂号 ￥" + ((postal-0) + (registered-0) + num);
		}
		element.options[1].attributes.price.value = ((postal-0) + (registered-0) + num);
	}	
}
//优惠
function promotionPostage(courier,postal,registered,prior_charges,extra_courier,element){
	prior_charges = 1;
	
	var heji = 0;
	var table = $(element).parents("table")		
	$(".xiaoji",table).each(function(index, element) {
		heji += element.innerHTML.replace("￥","")-0;
	});
	
	if (heji>=prior_charges-0){
		clearPostal(element,1);
		
		return true;
	}else{
		var num = 0;
		$(element).parents("table").find(".num").each(function(index, element) {
			num += (element.innerHTML - 0);
		});
		
		num -= 1;
		num = parseInt(num/2)*5;
		if(parseInt(num/2)*5>10){
			num = 10;
		};	
		
		if (courier == "0"){
			element.options[0].text = "快递 免运费"
		}else{
			element.options[01].text = "快递 ￥" + ((courier-0)+num);
		}	
		element.options[0].attributes.price.value = ((postal-0)+num);;
		
		if ((postal-0) + (registered-0)== 0){
			element.options[1].text = "挂号 免运费"
		}else{
			element.options[1].text = "挂号 ￥" + ((postal-0) + (registered-0) + num);
		}
		element.options[1].attributes.price.value = ((postal-0) + (registered-0) + num);
		
		return false;
	}	
}
//期刊
function categoryPostage(courier,postal,registered,prior_charges,extra_courier,element){
	//prior_charges = 1000;//测试用
	var heji = 0;
	var table = $(element).parents("table")		
	$(".xiaoji",table).each(function(index, element) {
		heji += element.innerHTML.replace("￥","")-0;
	});
	
	if (prior_charges== "" || heji>=prior_charges-0){
		clearPostal(element,0);
		return true;
	}else{
		element.options[0].text = "平邮 免运费"
		element.options[0].attributes.price.value = 0;
		
		if (courier == "0"){
			element.options[1].text = "快递 免运费"
		}else{
			element.options[1].text = "快递 ￥" + ((extra_courier-0)*12);
		}	
		element.options[1].attributes.price.value = (extra_courier-0)*12;
		
		if ((registered-0)== 0){
			element.options[2].text = "挂号 免运费"
		}else{
			element.options[2].text = "挂号 ￥" + ((registered-0)*12);
		}
		element.options[2].attributes.price.value = (registered-0)*12;
		
		return false;
	}	
}

function sendOrder(){
	var select_addr_id = $("#select_addr_id").val();
	if(select_addr_id=="" || select_addr_id=="0"){
		alert("请选择收货地址");
		return false;
	}else{
		if ($(".jiesuaninfo .qinyoucheck").attr("checked")){
			var qinyou = $(".jiesuaninfo .qinyou").val();
			if(qinyou!="输入亲友的帐号"){
				$(".jiesuaninfo .u_referrer").val(qinyou);
			}else{
				$(".jiesuaninfo .u_referrer").val("");
			}
		}else{
			$(".jiesuaninfo .u_referrer").val("");
		}
		$("#form1").submit();
	}
	
	/*//收货地址ID
	var select_addr_id = $("#select_addr_id").val();
	if(select_addr_id=="" || select_addr_id=="0"){
		alert("请选择收货地址");
		return false;
	}else{
		alert("收货地址ID："+select_addr_id);
	}
	
	//订单留言
	var ordermessage = $("#order_note").val();
	alert("留言："+ordermessage);
	
	//推荐人
	var qinyoucheck = $(".jiesuaninfo .fujia .qinyoucheck").get(0).checked;
	var qinyou = $(".jiesuaninfo .fujia .qinyou").val();
	if (qinyoucheck && qinyou != "输入亲友ID"){
		alert("推荐人："+qinyou);
	}
	
	//邮费
	var postagetype = new Array();
	$(".orderdata .postagetype").each(function(index, element) {
		alert(element.name+"："+element.options[element.selectedIndex].value);
	});*/
}

function clearPostal(element,type){
	if (type==0){
		element.options[0].text = "平邮 免运费"
		element.options[0].attributes.price.value = 0;
		
		element.options[1].text = "快递 免运费"
		element.options[1].attributes.price.value = 0;
		element.selectedIndex = 1;
		
		element.options[2].text = "挂号 免运费"
		element.options[2].attributes.price.value = 0;
	}else{
		element.options[0].text = "快递 免运费"
		element.options[0].attributes.price.value = 0;
		element.selectedIndex = 0;
		
		element.options[1].text = "挂号 免运费"
		element.options[1].attributes.price.value = 0;
	}
}

var onOff = true;
function see(){
	//浏览器可视区域的高度
	var see = document.documentElement.clientHeight;    
	//滚动条滑动的距离
	var winScroll = $(this).scrollTop();
	//每个UL的最后一个LI，距离浏览器顶部的
	var lastLisee = $(".foot").offset().top
	return lastLisee < (see+winScroll)?true:false;        
}
	
function initPinterest(){
	$("#cur_page").val(1);
	var $container = $('.imglist');

	$container.imagesLoaded( function(){
		$container.masonry({
			itemSelector : '.imgbox',
			columnWidth : 200
		});
	});
	
	$(window).scroll(function(){
		if(onOff && see()){
			getImg($container);
		}
	})
	
	getImg($container);
}
function getImg($container){
	onOff = false;
	
	var book_id = $("#book_id").val();
	var order_type = $("#order_type").val();
	var cur_page = $("#cur_page").val();
	
	//Images!loadImages.action
	$.post("getImg.xml",{id:book_id,type:order_type,page:cur_page,rows:3},function(data){
		var imgList = "";
		$(data).find("images").each(function(index, element){
			var imgSrc = $(element).find("path").text();
			var imgLi = '<div class="imgbox"><a href="javascript:;"><img src="'+imgSrc+'" width="180" /></a></div>';
			imgList += imgLi;
		});
		
		var el = $(imgList);
		
		$('.imglist').append(el)
		el.fadeTo(0,0);
		
		el.imagesLoaded(function(){
				$container.masonry( 'appended', el, true );
				el.fadeTo(0,1);
		});
		
		el.find("img").click(bindImg);
				
		window.setTimeout(initScrollState,200);
	},"xml");
}

function initScrollState(){
	onOff = true;
	var next_page = $("#cur_page").val()-0+1;
	$("#cur_page").val(next_page)
}

function openUrl( url ){
	 var f=document.createElement("form");
	 f.setAttribute("action" , url );
	 f.setAttribute("method" , 'get' );
	 f.setAttribute("target" , '_black' );
	 
	 var subject1=document.createElement("input");
	 subject1.type="hidden";
	 subject1.value="";//参数值
	 subject1.name="subject";//参数名
	 f.appendChild(subject1);
	 
	 var subject2=document.createElement("input");
	 subject2.type="hidden";
	 subject2.value="";//参数值
	 subject2.name="subject";//参数名
	 f.appendChild(subject2);
	 
	 var subject3=document.createElement("input");
	 subject3.type="hidden";
	 subject3.value="";//参数值
	 subject3.name="subject";//参数名
	 f.appendChild(subject3);
	 
	 var subject4=document.createElement("input");
	 subject4.type="hidden";
	 subject4.value="";//参数值
	 subject4.name="subject";//参数名
	 f.appendChild(subject4);
	 
	 document.body.appendChild(f)
	 f.submit();
}